<script setup>
import { main } from "./store";
import { onMounted, onBeforeUnmount, watch, ref } from "vue"
import mp3 from "./assets/BackgroundMusic.mp3"
import { SetMusic, GetMusic, ClearMusic } from "./utils/Token"
const Main = main()
const audio = ref()
const app = ref()
const Setting = ref(false)
onBeforeUnmount(() => {
  Main.ExpTimer ? clearInterval(Main.ExpTimer) : ""
})
Main.Mozilla()

onMounted(() => {
  audio.value = document.createElement("audio")
  audio.value.setAttribute("src", mp3)
  audio.value.setAttribute("loop", true)
  Setting.value = true
  ClearMusic()
  SetMusic("close")
  // 获取全局dom元素
  app.value = document.querySelector("#app")


})
watch(() => Main.MP3, () => {
  mp3Fn()
})
watch(() => Main.Screen, () => {
  FullScreen()

})

// 控制是否全屏
const FullScreen = () => {
  // const isFullScreen = document.webkitIsFullScreen
  // const isFullScreen = document.fullscreen
  // const isFullScreen = document.msFullscreenElement
  // const isFullScreen = document.mozFullScreen
  // if (Main.Screen == 1) {
  //   app.value.requestFullscreen()
  // } else {
  //   // app.value.exitFullscreen()
  //   document.exitFullscreen()
  // }
  if (document.fullscreenElement) {
    document.exitFullscreen()
  } else {
    app.value.requestFullscreen()
  }

}

// 控制音乐播放
const mp3Fn = () => {
  const music = GetMusic()
  if (music.split("-")[0] == "play") {
    audio.value.play()
  } else if (music.split("-")[0] == "close") {
    audio.value.pause();
  }
}

window.addEventListener("keydown", (e) => {
  if (e.code == "F11") {
    e.preventDefault()
  }
})
</script>

<template>
  <router-view></router-view>
  <!-- <Zky_Popup v-model:hidden="Setting" :title="'开篇'" :overflowhidden="!Main.MozillaText" :CancelHidden="false"
    :Confirm="Confirm">
    <div class="SettingBox">
      欢迎来到很无聊且不好玩的模拟修仙世界
    </div>
  </Zky_Popup> -->
</template>

